package com.afkt.project.ui.adapter;



import com.ohos.afkt.ResourceTable;
import com.dev.utils.app.ViewUtils;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.PageSliderProvider;
import ohos.agp.components.Text;

import java.util.List;

public class ViewPagerAdapter extends PageSliderProvider {

    private List<String> lists;

    public ViewPagerAdapter(List<String> lists) {
        this.lists = lists;
    }


    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int position) {
        Component view = ViewUtils.inflate(ResourceTable.Layout_view_pager_item_view);

        // 设置文本
       Text text = ((Text) view.findComponentById(ResourceTable.Id_vid_vpiv_content_tv));
       text.setText(lists.get(position % lists.size()));
        componentContainer.addComponent(view);
        return view;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {

        componentContainer.removeComponent((Component) o);
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return component == o;
    }
}
